package com.xyh.collapser;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCollapser;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.xyh.Member;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
@Service
public class CollService {
    @HystrixCollapser(batchMethod = "getMembers",collapserProperties = {
            @HystrixProperty(name="timerDelayInMilliseconds",value = "1000")
    })
    public Future<Member> getMember(Integer id){
        System.out.println("执行单个的查询的方法");
        return null;
    }
    @HystrixCommand
    public List<Member> getMembers(List<Integer> ids){
        List<Member> members=new ArrayList<Member>();
        for(Integer id:ids){
            System.out.println(id);
            Member m=new Member();
            m.setName("angus");
            m.setId(id);
            members.add(m);
        }
        return members;
    }
}
